package com.sqly.doc.menu.yyye;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.support.annotation.IdRes;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ihidea.multilinechooselib.MultiLineChooseLayout;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sqly.doc.R;
import com.sqly.doc.base.MyBaseActivity;
import com.sqly.doc.menu.camera.CameraChoose;
import com.sqly.doc.menu.tnb.tnb;
import com.sqly.doc.pojo.JuMin;
import com.sqly.doc.pojo.RetMsg;
import com.sqly.doc.pojo.XseShiErYueEtjkjc;
import com.sqly.doc.user.choose_user;
import com.sqly.doc.util.CreateBitmap;
import com.sqly.doc.util.DateConvert;
import com.sqly.doc.util.HttpUrl;
import com.sqly.doc.util.MyToastUtil;
import com.sqly.doc.util.NetWorkUtils;
import com.sqly.doc.util.SharedPreferencesUtils;
import com.sqly.doc.util.SweetAlertDialogUtil;
import com.sqly.doc.util.Url;
import com.sqly.doc.util.UserClient;
import com.sqly.doc.util.WriteActivity;
import com.sqly.doc.view.CustomDatePicker;
import com.sqly.doc.view.StringUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

//import cn.pedant.SweetAlert.SweetAlertDialog;
import com.cazaea.sweetalert.SweetAlertDialog;

import cz.msebera.android.httpclient.Header;

/**
 */

public class yyye_24 extends MyBaseActivity {

    XseShiErYueEtjkjc obj;
    private CustomDatePicker customDatePicker;
    Context con = yyye_24.this;
    //标题
    TextView title, uname;
    //转诊
    EditText zzyy, jgjkb, lxr, lxdh;
    RadioGroup zzjg, bt;
    String zzjgs = "";
    TextView xcsfrq, bcsfrq;
    ////////////////////////////////////////////////////////////
    RadioGroup tz, sg, ms, pf, qx, jbbk, yj, er, kq, xb, fb, qb, sz, gmwszq, tl;
    EditText tzs, sgs, tw, qx1, qx2, hwhd, fywssd, zdqt, cys, qcs;
    CheckBox hbqk_wu, hbqk_fy, hbqk_fx, hbqk_qt, hbqk_ws;
    EditText wudes, fydes, fxdes, wsdes, qtdes;
    MultiLineChooseLayout bjzd, kyglzz, kygltz, fypg;
    private List<String> bjzddata = new ArrayList<>();
    private List<String> kyglzzdata = new ArrayList<>();
    private List<String> kygltzdata = new ArrayList<>();
    private List<String> fypgdata = new ArrayList<>();
    String JKDAH = "";
    boolean isadd = false;//是否是新添加
    String url = "";
    ImageView sfysqm, brqm, xcqm;
    String sfysqmpic = "", brqmpic = "",xcqmpic ="";
    JuMin j;
    TextView xm;

    ImageView xcpaizhao;
    TextView pz_record_id,jmqm_record_id, ysqm_record_id;
    boolean pzChange = false;
    LinearLayout back;

    @Override
    protected void initUI() {
        setContentView(R.layout.et_24);
        if (NetWorkUtils.isNetworkConnected(con)) {
            if (getIntent().getStringExtra("type").equals("edit")) {
                obj = (XseShiErYueEtjkjc) getIntent().getExtras().getSerializable("b");
                init();
                if(!StringUtils.isEmpty(obj.getImg())){
                    ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg()),brqm);
                }
                if(!StringUtils.isEmpty(obj.getImg1())){
                    ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg1()),sfysqm);
                }
                if(!StringUtils.isEmpty(obj.getImg2())){
                    ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg2()),xcqm);
                }
                xm.setClickable(false);
            }else {
                obj = new XseShiErYueEtjkjc();
                init();
            }
        }

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {

        } else if (requestCode == 1) {
            j = (JuMin) data.getExtras().getSerializable("j");
            getObject();
        }else if (requestCode == 8) {
            String record_id = (String) data.getExtras().getString("record_id");
            ysqm_record_id.setText(record_id);
            byte[] bis = data.getByteArrayExtra("bitmap");
            Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
            Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
            sfysqm.setImageBitmap(bb);
            sfysqmpic = CreateBitmap.saveMyBitmap(bb);
        }else if (requestCode == 9) {
            String record_id = (String) data.getExtras().getString("record_id");
            jmqm_record_id.setText(record_id);
            byte[] bis = data.getByteArrayExtra("bitmap");
            Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
            Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
            brqm.setImageBitmap(bb);
            brqmpic = CreateBitmap.saveMyBitmap(bb);
        }else if(requestCode == 119){
            String img_record_id = (String) data.getExtras().getString("img_record_id");
            pz_record_id.setText(img_record_id);
            pzChange = true;
            byte[] bis = data.getByteArrayExtra("bitmap");
            Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
            Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
            xcqm.setImageBitmap(bb);
        }
    }

    public void init() {
        //医生签名
        sfysqm = (ImageView) findViewById(R.id.sfysqm);
        if (obj != null && !StringUtils.isEmpty(obj.getSfysqm())) {
            sfysqmpic = obj.getSfysqm();
            sfysqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + sfysqmpic + ".jpg"));
        }
        sfysqm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(con, WriteActivity.class)
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "xseEtjktj12")
                        .putExtra("imageType", "img1")
                        .putExtra("class", "yyye_24.class"), 8);
            }
        });
        //本人签名
        brqm = (ImageView) findViewById(R.id.brqm);
        if (obj != null && !StringUtils.isEmpty(obj.getBrqm())) {
            brqmpic = obj.getBrqm();
            brqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + brqmpic + ".jpg"));
        }
        brqm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(con, WriteActivity.class)
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "xseEtjktj12")
                        .putExtra("imageType", "img")
                        .putExtra("class","yyye_24.class"), 9);
            }
        });
        xcqm = (ImageView) findViewById(R.id.xcqm);
        if (obj != null && !StringUtils.isEmpty(obj.getXcqm())) {
            xcqmpic = obj.getXcqm();
            xcqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + xcqmpic + ".jpg"));
        }
        xcqm.setOnClickListener(new CustomerListener());
        xm = (TextView) findViewById(R.id.XINGMING);
        if (obj != null && !StringUtils.isEmpty(obj.getXINGMING())) {
            xm.setText(obj.getXINGMING());
        } else {
            xm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivityForResult(new Intent(con, choose_user.class).putExtra("cname", "yyye_24.class"), 1);
                }
            });
        }
        //现场拍照
        xcpaizhao = (ImageView) findViewById(R.id.xcpaizhao);
        xcpaizhao.setOnClickListener(new CustomerListener());
        //现场拍照照片id
        pz_record_id = (TextView) findViewById(R.id.pz_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg2())) {
            //fjhdycrhsf/D24E75C5BB5E417EBE65494CA09BF399.jpg
            String[] img2Arr =obj.getImg2().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                pz_record_id.setText(img2Arr[1]);
            }
        }
        jmqm_record_id= (TextView) findViewById(R.id.jmqm_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg())) {
            String[] img2Arr =obj.getImg().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                jmqm_record_id.setText(img2Arr[1]);
            }
        }
        ysqm_record_id= (TextView) findViewById(R.id.ysqm_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg1())) {
            //fjhdycrhsf/D24E75C5BB5E417EBE65494CA09BF399.jpg
            String[] img2Arr =obj.getImg1().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                ysqm_record_id.setText(img2Arr[1]);
            }
        }

        //标题
        title = (TextView) findViewById(R.id.title);
        uname = (TextView) findViewById(R.id.uname);
        title.setText("24月龄儿童健康检查记录");
        back = (LinearLayout)findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(pzChange){
                   SweetAlertDialogUtil.WarningDialogHaveCancelAndConfirm(con,"你确认不保存数据更新吗？","现场拍照已经采集，请注意点击“保存”","确定", "返回");
                }else {
                    finish();
                }
            }
        });
        uname.setText("保存");
        uname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null == xm.getText().toString() || "".equals(xm.getText().toString())){
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "姓名不能为空");
                }else if(null == bcsfrq.getText().toString() || "".equals(bcsfrq.getText().toString())){
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "本次随访日期不能为空");
                } else if(null == xcsfrq.getText().toString() || "".equals(xcsfrq.getText().toString())){
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "下次随访日期不能为空");
                } else if ("1".equals(SharedPreferencesUtils.getParam(con, "ysqm", "0").toString()) && ysqm_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "随访医生签名不能为空");
                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "jmqm", "0").toString()) && jmqm_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "家属或本人签名不能为空");
                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "xcpz", "0").toString()) && pz_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "现场拍照不能为空");
                } else {
                    if (obj == null)
                        obj = new XseShiErYueEtjkjc();
                    obj.setXINGMING(xm.getText().toString());
                    obj.setTZQK(tzs.getText().toString());
                    obj.setSCQK(sgs.getText().toString());
                    obj.setQL1(qx1.getText().toString());
                    obj.setQL2(qx2.getText().toString());
                    obj.setCYS(cys.getText().toString());
                    obj.setQCS(qcs.getText().toString());

                    obj.setHWHD(hwhd.getText().toString());
                    obj.setFYWSSD(fywssd.getText().toString());

                    String res = "";
                    if (hbqk_wu.isChecked())
                        res = res + ",1";
                    if (hbqk_fy.isChecked())
                        res = res + ",1";
                    if (hbqk_fx.isChecked())
                        res = res + ",2";
                    if (hbqk_ws.isChecked())
                        res = res + ",3";
                    if (hbqk_qt.isChecked())
                        res = res + ",4";
                    obj.setLCSFJHBQK(res);
                    obj.setFEIYAN(fydes.getText().toString());
                    obj.setFUXIE(fxdes.getText().toString());
                    obj.setWAISHANG(wsdes.getText().toString());
                    obj.setQT(qtdes.getText().toString());
                    ArrayList<Integer> zdlist = bjzd.getAllItemSelectedIndex();
                    String ads = "";
                    for (int i = 0; i < zdlist.size(); i++) {
                        if (i == 0)
                            ads = zdlist.get(i) + "";
                        else
                            ads = ads + "," + zdlist.get(i);
                    }
                    obj.setZHIDAO(ads);

                    ArrayList<Integer> tzlist = kygltz.getAllItemSelectedIndex();
                    String tzs = "";
                    for (int i = 0; i < tzlist.size(); i++) {
                        if (i == 0)
                            tzs = tzlist.get(i) + "";
                        else
                            tzs = tzs + "," + tzlist.get(i);
                    }
                    obj.setKYGLBTZ(tzs);
                    ArrayList<Integer> fypglist = fypg.getAllItemSelectedIndex();
                    String pgs = "";
                    for (int i = 0; i < fypglist.size(); i++) {
                        if (i == 0)
                            pgs = fypglist.get(i) + "";
                        else
                            pgs = pgs + "," + fypglist.get(i);
                    }
                    obj.setFYPG(pgs);
                    obj.setZDQT(zdqt.getText().toString());
                    obj.setZZYY(zzyy.getText().toString());
                    obj.setZZJGJKS(jgjkb.getText().toString());
                    obj.setZZLXR(lxr.getText().toString());
                    obj.setZZLXFS(lxdh.getText().toString());
                    obj.setSFRQ(bcsfrq.getText().toString());
                    obj.setXCSFRQ(xcsfrq.getText().toString());

                    if (NetWorkUtils.isNetworkConnected(con)) {//网络存在
                        RequestParams ps = new RequestParams();
                        ps.add("entity.SFRQ", obj.getSFRQ());
                        ps.add("entity.TIZHONG", obj.getTIZHONG());
                        ps.add("entity.TZQK", obj.getTZQK());
                        ps.add("entity.SCQK", obj.getSCQK());
                        ps.add("entity.SHENCHANG", obj.getSHENCHANG());
                        ps.add("entity.MIANSE", obj.getMIANSE());
                        ps.add("entity.PIFU", obj.getPIFU());
                        ps.add("entity.QL2", obj.getQL2());
                        ps.add("entity.QL1", obj.getQL1());
                        ps.add("entity.QLQK", obj.getQLQK());
                        ps.add("entity.YWG", obj.getYWG());
                        ps.add("entity.EWG", obj.getEWG());
                        ps.add("entity.CYS", obj.getCYS());
                        ps.add("entity.XINFEI", obj.getXINFEI());
                        ps.add("entity.FUBU", obj.getFUBU());
                        ps.add("entity.SIZHI", obj.getSIZHI());
                        ps.add("entity.HWHD", obj.getHWHD());
                        ps.add("entity.FYWSSD", obj.getFYWSSD());
                        ps.add("entity.LCSFJHBQK", obj.getLCSFJHBQK());
                        ps.add("entity.LCSFJHBQT", obj.getLCSFJHBQT());
                        ps.add("entity.ZHIDAO", obj.getZHIDAO());
                        ps.add("entity.ZDQT", obj.getZDQT());
                        ps.add("entity.TINGLI", obj.getTINGLI());
                        ps.add("entity.ZZYY", obj.getZZYY());
                        ps.add("entity.ZZJGJKS", obj.getZZJGJKS());
                        ps.add("entity.ZZLXR", obj.getZZLXR());
                        ps.add("entity.ZZLXFS", obj.getZZLXFS());
                        ps.add("entity.ZZJG", obj.getZZJG());
                        ps.add("entity.SFRQ", obj.getSFRQ());
                        ps.add("entity.XCSFRQ", obj.getXCSFRQ());
                        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
                        ps.add("type", "2");
                        ps.add("entity.XINGMING", obj.getXINGMING());
                        ps.add("entity.YUELING", "24");
                        ps.add("entity.CARDNUM", obj.getCARDNUM());
                        if (isadd) {
                            ps.add("entity.JKDAH", JKDAH);
                            url = HttpUrl.SaveYE12Sfjl;
                        } else {
                            ps.add("entity.SFJLH", obj.getSFJLH());
                            ps.add("entity.JKDAH", obj.getJKDAH());
                            url = HttpUrl.EditYE12Sfjl;
                        }

                        ps.add("pz_record_id", pz_record_id.getText().toString());
                        ps.add("jmqm_record_id", jmqm_record_id.getText().toString());
                        ps.add("ysqm_record_id", jmqm_record_id.getText().toString());
                        ps.add("entity.UPDATETIME", obj.getUPDATETIME());
                        //yyye_24.super.ImageUploadOperate(sfysqmpic, brqmpic, ps);
                        UserClient.get(url, ps, new AsyncHttpResponseHandler() {
                            @Override
                            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                                String content = new String(response);
                                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                                if (ret.getCode().equals("200")) {
                                    MyToastUtil.ShowToast(con, "成功");
                                }else{
                                    MyToastUtil.ShowToast(con, ret.getInfo());
                                }
                                finish();
                            }

                            @Override
                            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                                MyToastUtil.ShowToast(con, "失败");
                            }
                        });
                    }
                }
            }
        });
        //转诊
        bt = (RadioGroup) findViewById(R.id.bt);
        if (obj != null && !StringUtils.isEmpty(obj.getFUBU())) {
            switch (Integer.parseInt(obj.getFUBU())) {
                case 1:
                    bt.check(R.id.bt_wjyc);
                    break;
                case 2:
                    bt.check(R.id.bt_yc);
                    break;


            }
        }
        bt.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.bt_wjyc) {
                    obj.setBUTAI("1");
                } else {
                    obj.setBUTAI("2");
                }
            }
        });
        zzyy = (EditText) findViewById(R.id.zz_yy);
        if (obj != null && !StringUtils.isEmpty(obj.getZZYY())) {
            zzyy.setText(obj.getZZYY());
        }
        jgjkb = (EditText) findViewById(R.id.zzjg);
        if (obj != null && !StringUtils.isEmpty(obj.getZZJG())) {
            jgjkb.setText(obj.getZZJG());
        }
        lxr = (EditText) findViewById(R.id.zz_lxr);
        if (obj != null && !StringUtils.isEmpty(obj.getZZLXR())) {
            lxr.setText(obj.getZZLXR());
        }

        lxdh = (EditText) findViewById(R.id.zz_lxfs);
        if (obj != null && !StringUtils.isEmpty(obj.getZZLXFS())) {
            lxdh.setText(obj.getZZLXFS());
        }
        zzjg = (RadioGroup) findViewById(R.id.jg);
        if (obj != null && !StringUtils.isEmpty(obj.getZZJG())) {
            switch (Integer.parseInt(obj.getZZJG())) {
                case 1:
                    zzjg.check(R.id.dw);
                    break;
                case 2:
                    zzjg.check(R.id.wdw);
                    break;
            }
        }
        zzjg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                if (checkedId == R.id.dw)
                    obj.setZZJG("1");
                else
                    obj.setZZJG("2");
            }
        });
        xcsfrq = (TextView) findViewById(R.id.xcsfrq);
        if (obj != null && !StringUtils.isEmpty(obj.getXCSFRQ())) {
            xcsfrq.setText(DateConvert.dateToString(DateConvert.toDate(obj.getXCSFRQ(), DateConvert.YMD), DateConvert.YMD)+"");
        }
        xcsfrq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        xcsfrq.setText(time.split(" ")[0]);

                    }
                }, DateConvert.getCustomDatePickerStartRq(), DateConvert.getCustomDatePickerEndRq()); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(DateConvert.getCustomDatePickerNowRq());
            }
        });
        bcsfrq = (TextView) findViewById(R.id.sfrq);
        if (obj != null && !StringUtils.isEmpty(obj.getSFRQ())) {
            bcsfrq.setText(DateConvert.dateToString(DateConvert.toDate(obj.getSFRQ(), DateConvert.YMD), DateConvert.YMD)+"");
        }
        bcsfrq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                String now = sdf.format(new Date());
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        bcsfrq.setText(time.split(" ")[0]);

                    }
                }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(now);
            }
        });
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        bjzd = (MultiLineChooseLayout) findViewById(R.id.zhidao);
        bjzddata.add("科学喂养");
        bjzddata.add("生长发育");
        bjzddata.add("疾病预防");
        bjzddata.add("预防伤害");
        bjzddata.add("口腔保健");
        bjzddata.add("其他");
        bjzd.setList(bjzddata);
        if (obj != null && !StringUtils.isEmpty(obj.getZHIDAO())) {
            if (obj.getZHIDAO().contains("1"))
                bjzd.setIndexItemSelected(0);
            if (obj.getZHIDAO().contains("2"))
                bjzd.setIndexItemSelected(1);
            if (obj.getZHIDAO().contains("3"))
                bjzd.setIndexItemSelected(2);
            if (obj.getZHIDAO().contains("4"))
                bjzd.setIndexItemSelected(3);
            if (obj.getZHIDAO().contains("5"))
                bjzd.setIndexItemSelected(4);
            if (obj.getZHIDAO().contains("6"))
                bjzd.setIndexItemSelected(5);
        }

        zdqt = (EditText) findViewById(R.id.zd_qt);
        if (obj != null && !StringUtils.isEmpty(obj.getZDQT())) {
            zdqt.setText(obj.getZDQT());
        }
        tz = (RadioGroup) findViewById(R.id.tz);
        if (obj != null && !StringUtils.isEmpty(obj.getTIZHONG())) {
            switch (Integer.parseInt(obj.getTIZHONG())) {
                case 1:
                    tz.check(R.id.tz_shang);
                    break;
                case 2:
                    tz.check(R.id.tz_zhong);
                    break;
                case 3:
                    tz.check(R.id.tz_xia);
                    break;

            }
        }
        tz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.tz_shang) {
                    obj.setTIZHONG("1");
                } else if (i == R.id.tz_zhong) {
                    obj.setTIZHONG("2");
                } else {

                }
            }
        });
        tzs = (EditText) findViewById(R.id.tzs);
        if (obj != null && !StringUtils.isEmpty(obj.getTZQK())) {
            tzs.setText(obj.getTZQK());
        }
        sg = (RadioGroup) findViewById(R.id.sg);
        if (obj != null && !StringUtils.isEmpty(obj.getSCQK())) {
            switch (Integer.parseInt(obj.getSCQK())) {
                case 1:
                    sg.check(R.id.sg_shang);
                    break;
                case 2:
                    sg.check(R.id.sg_zhong);
                    break;
                case 3:
                    sg.check(R.id.sg_xia);
                    break;

            }
        }
        sg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.sg_shang) {
                    obj.setSCQK("1");
                } else if (i == R.id.sg_zhong) {
                    obj.setSCQK("2");
                } else {
                    obj.setSCQK("3");
                }
            }
        });
        sgs = (EditText) findViewById(R.id.sg_yc);
        if (obj != null && !StringUtils.isEmpty(obj.getSHENCHANG())) {
            sgs.setText(obj.getSHENCHANG());
        }
        ////////////////////////////////////////////////////////////体格检查
        ms = (RadioGroup) findViewById(R.id.ms);
        if (obj != null && !StringUtils.isEmpty(obj.getMIANSE())) {
            switch (Integer.parseInt(obj.getMIANSE())) {
                case 1:
                    ms.check(R.id.ms_hr);
                    break;
                case 2:
                    ms.check(R.id.ms_h);
                    break;
                case 3:
                    ms.check(R.id.ms_qt);
                    break;

            }
        }
        ms.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.ms_hr) {
                    obj.setMIANSE("1");
                } else if (i == R.id.ms_h) {
                    obj.setMIANSE("2");
                } else {
                    obj.setMIANSE("3");
                }
            }
        });
        pf = (RadioGroup) findViewById(R.id.pf);
        if (obj != null && !StringUtils.isEmpty(obj.getPIFU())) {
            switch (Integer.parseInt(obj.getPIFU())) {
                case 1:
                    pf.check(R.id.pf_wjyc);
                    break;
                case 2:
                    pf.check(R.id.pf_yc);
                    break;
            }
        }
        pf.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.pf_wjyc) {
                    obj.setPIFU("1");
                } else {
                    obj.setPIFU("2");
                }
            }
        });
        qx1 = (EditText) findViewById(R.id.qx1);
        if (obj != null && !StringUtils.isEmpty(obj.getQL1())) {
            qx1.setText(obj.getQL1());
        }
        qx2 = (EditText) findViewById(R.id.qx2);
        if (obj != null && !StringUtils.isEmpty(obj.getQL2())) {
            qx2.setText(obj.getQL2());
        }
        qx = (RadioGroup) findViewById(R.id.qx);
        if (obj != null && !StringUtils.isEmpty(obj.getQLQK())) {
            switch (Integer.parseInt(obj.getQLQK())) {
                case 1:
                    qx.check(R.id.qx_bh);
                    break;
                case 2:
                    qx.check(R.id.qx_wb);
                    break;
            }
        }
        qx.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.qx_bh) {
                    obj.setQLQK("1");
                } else
                    obj.setQLQK("2");
            }
        });
        yj = (RadioGroup) findViewById(R.id.yj);
        if (obj != null && !StringUtils.isEmpty(obj.getYWG())) {
            switch (Integer.parseInt(obj.getYWG())) {
                case 1:
                    yj.check(R.id.yj_wjyc);
                    break;
                case 2:
                    yj.check(R.id.yj_yc);
                    break;


            }
        }
        yj.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.yj_wjyc) {
                    obj.setYWG("1");
                } else {
                    obj.setYWG("2");
                }
            }
        });
        er = (RadioGroup) findViewById(R.id.er);
        if (obj != null && !StringUtils.isEmpty(obj.getEWG())) {
            switch (Integer.parseInt(obj.getEWG())) {
                case 1:
                    er.check(R.id.er_wjyc);
                    break;
                case 2:
                    er.check(R.id.er_yc);
                    break;


            }
        }
        er.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.er_wjyc) {
                    obj.setEWG("1");
                } else {
                    obj.setEWG("1");
                }
            }
        });
        cys = (EditText) findViewById(R.id.cys);
        if (obj != null && !StringUtils.isEmpty(obj.getCYS())) {
            cys.setText(obj.getCYS());
        }
        qcs = (EditText) findViewById(R.id.qcs);
        if (obj != null && !StringUtils.isEmpty(obj.getQCS())) {
            qcs.setText(obj.getQCS());
        }
        tl = (RadioGroup) findViewById(R.id.tl);
        if (obj != null && !StringUtils.isEmpty(obj.getTINGLI())) {
            switch (Integer.parseInt(obj.getTINGLI())) {
                case 1:
                    tl.check(R.id.tl_tg);
                    break;
                case 2:
                    tl.check(R.id.tl_wtg);
                    break;


            }
        }
        tl.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.tl_tg) {
                    obj.setTINGLI("1");
                } else {
                    obj.setTINGLI("2");
                }
            }
        });
        //////////////////////////////////////龋齿暂无
        xb = (RadioGroup) findViewById(R.id.xb);
        if (obj != null && !StringUtils.isEmpty(obj.getXINFEI())) {
            switch (Integer.parseInt(obj.getXINFEI())) {
                case 1:
                    xb.check(R.id.xb_wjyc);
                    break;
                case 2:
                    xb.check(R.id.xb_yc);
                    break;


            }
        }
        xb.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.xb_wjyc) {
                    obj.setXINFEI("1");
                } else {
                    obj.setXINFEI("2");
                }
            }
        });
        fb = (RadioGroup) findViewById(R.id.fb);
        if (obj != null && !StringUtils.isEmpty(obj.getFUBU())) {
            switch (Integer.parseInt(obj.getFUBU())) {
                case 1:
                    fb.check(R.id.fb_wjyc);
                    break;
                case 2:
                    fb.check(R.id.fb_yc);
                    break;


            }
        }
        fb.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.fb_wjyc) {
                    obj.setFUBU("1");
                } else {
                    obj.setFUBU("2");
                }
            }
        });
        sz = (RadioGroup) findViewById(R.id.sz);
        if (obj != null && !StringUtils.isEmpty(obj.getSIZHI())) {
            switch (Integer.parseInt(obj.getSIZHI())) {
                case 1:
                    sz.check(R.id.sz_wjyc);
                    break;
                case 2:
                    sz.check(R.id.sz_yc);
                    break;


            }
        }
        sz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.sz_wjyc) {
                    obj.setSIZHI("1");
                } else {
                    obj.setSIZHI("2");
                }
            }
        });
        kygltz = (MultiLineChooseLayout) findViewById(R.id.kygltz);
        kygltzdata.add("无");
        kygltzdata.add("肋串珠");
        kygltzdata.add("肋软骨沟");
        kygltzdata.add("鸡胸");
        kygltzdata.add("手足镯");
        kygltzdata.add("“O”型腿");
        kygltzdata.add("“X”型腿");
        kygltz.setList(kygltzdata);
        if (obj != null && !StringUtils.isEmpty(obj.getKYGLBTZ())) {
            if (obj.getKYGLBTZ().contains("1"))
                kygltz.setIndexItemSelected(0);
            if (obj.getKYGLBTZ().contains("2"))
                kygltz.setIndexItemSelected(1);
            if (obj.getKYGLBTZ().contains("3"))
                kygltz.setIndexItemSelected(2);
            if (obj.getKYGLBTZ().contains("4"))
                kygltz.setIndexItemSelected(3);
        }

        hwhd = (EditText) findViewById(R.id.hwhd);
        if (obj != null && !StringUtils.isEmpty(obj.getHWHD())) {
            hwhd.setText(obj.getHWHD());
        }
        fywssd = (EditText) findViewById(R.id.fywssd);
        if (obj != null && !StringUtils.isEmpty(obj.getFYWSSD())) {
            fywssd.setText(obj.getFYWSSD());
        }
        fypg = (MultiLineChooseLayout) findViewById(R.id.fypg);
        fypgdata.add("不会说3个物品的名称");
        fypgdata.add("不会按吩咐做简单事情");
        fypgdata.add("不会用勺吃饭");
        fypgdata.add("不会扶栏上楼/台阶");
        fypg.setList(fypgdata);
        if (obj != null && !StringUtils.isEmpty(obj.getFYPG())) {
            if (obj.getFYPG().contains(",")) {
                String[] ss = obj.getFYPG().split(",");
                for (int i = 0; i < ss.length; i++) {
                    if (!StringUtils.isEmpty(ss[i])) {
                        fypg.setIndexItemSelected(Integer.parseInt(ss[i]));
                    }
                }
            } else {
                fypg.setIndexItemSelected(Integer.parseInt(obj.getFYPG()));
            }
        }
        hbqk_wu = (CheckBox) findViewById(R.id.fl_wu);
        hbqk_fy = (CheckBox) findViewById(R.id.hbqk_fy);
        fydes = (EditText) findViewById(R.id.hbqk_fy_cs);
        hbqk_fx = (CheckBox) findViewById(R.id.hbqk_fx);
        fxdes = (EditText) findViewById(R.id.hbqk_fx_cs);
        hbqk_ws = (CheckBox) findViewById(R.id.hbqk_ws);
        wsdes = (EditText) findViewById(R.id.hbqk_ws_cs);
        hbqk_qt = (CheckBox) findViewById(R.id.hbqk_qt);
        qtdes = (EditText) findViewById(R.id.hbqk_qt_des);

        if (obj != null && !StringUtils.isEmpty(obj.getLCSFJHBQK())) {
            if (obj.getLCSFJHBQK().contains("1"))
                hbqk_wu.setChecked(true);
            if (obj.getLCSFJHBQK().contains("2"))
                hbqk_fy.setChecked(true);
            if (obj.getLCSFJHBQK().contains("3"))
                hbqk_fx.setChecked(true);
            if (obj.getLCSFJHBQK().contains("4"))
                hbqk_ws.setChecked(true);
            if (obj.getLCSFJHBQK().contains("5"))
                hbqk_qt.setChecked(true);
        }
    }

    public void getObject() {
        RequestParams ps = new RequestParams();
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("type", "2");
        ps.add("SFCS", "24");
        ps.add("CARDNUM", j.getCARDNUM());
        UserClient.get(HttpUrl.GetYE12Grjbxx, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                Log.i("ycf2", content);
                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                if (ret.getCode().equals("200")) {
                    if (StringUtils.isEmpty(ret.getOtherParams())) {//other是空的
                        JSONObject j = JSON.parseObject(ret.getRd());
                        init();
                        obj = new XseShiErYueEtjkjc();
                        obj.setJKDAH(j.getString("JKDAH"));
                        obj.setXINGMING(j.getString("XINGMING"));
                        JKDAH = j.getString("JKDAH");
                        xm.setText(j.getString("XINGMING"));
                        obj.setCARDNUM(j.getString("CARDNUM"));
                        isadd = true;
                    } else {
                        isadd = false;
                        obj = JSON.parseObject(ret.getRd(), XseShiErYueEtjkjc.class);
                        init();
                    }
                }else{
                    SweetAlertDialogUtil.ErrorDialogNoFinish(con, "错误提示", ret.getInfo(), "确定");
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                obj = new XseShiErYueEtjkjc();
                init();
            }
        });
    }

    private class CustomerListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            if(obj != null && StringUtils.isEmpty(obj.getJKDAH())) {
                SweetAlertDialogUtil.WarningDialog(con, "提示", "选择居民用户后才能现场拍照");
            }else {
                Intent intent = new Intent(con, CameraChoose.class)
                        .putExtra("type", "edit")
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "xseEtjktj12")
                        .putExtra("class", "yyye_24.class");
                startActivityForResult(intent, 119);
            }
        }
    }
}
